<?php
include_once 'mysql_connect.php';

if(isset($_GET['show']))
{	
	echo "&nbsp;<hr />&nbsp".$_GET['show'];
}

/*change infor*/
$user_mess=$_GET['change_infor'];
$user_mess=explode(",",$user_mess);
$uid=$user_mess['0'];
$mess=$user_mess['1'];
//change password if--POST--
if(isset($_POST['pwsub']))
{	
	if((strlen($_POST['password'])) < 7 || (strlen($_POST['password'])) > 33 )
	{
		$message="此密码长度为<font color=red>".strlen($_POST['password'])."</font>请保持在7-32之间";
		header("location:show.php?show=$message");
	}
	else
	{
		$password=md5($_POST['password']);
		$pw=mysql_query("UPDATE `member` SET `password`='$password' WHERE `uid`='$uid'");
		header("location:user_zone.php?uid=$uid");
	}
}
//change username if--POST--
if(isset($_POST['unsub']))
{
	$username=$_POST['username'];
	if($username=='')
	{
		$message="用户名不能为空";
		header("location:show.php?show=$message");
	}
	elseif((strlen($_POST['username'])) < 5 || (strlen($_POST['username'])) > 33)
	{
		$message="用户名<font color=red>$username</font>的长度为为<font color=red>".strlen($_POST['username'])."</font>请保持在5-32之间无效，请重新输入";
		header("location:show.php?show=$message");

	}
	elseif(mysql_query("UPDATE `member` SET `username`='$username' WHERE `uid`='$uid'"))
	{	
		header("location:user_zone.php?uid=$uid");
	}
	else
	{	
		$message="未知错误";
		header("location:show.php?show=$message");
	}
}
//change password
if($mess=="password")
{
	//"修改密码";
	$pw=mysql_query("SELECT `username` FROM `member` WHERE `uid`='$uid'");
	$pw=mysql_fetch_array($pw);
	$pw=$pw['username'];
?>	
	<form action="" method="post" />
	<table border="1" align="center">
		<tr>
			<td align="right">用户名：</td><td><font color="red"><?php echo $pw ; ?></font></td>
		</tr>
		<tr>
			<td align="right">密码：</td><td><input type="password" name="password" maxlength="25" size="25" /></td>
		</tr>
		<tr>
			<td colspan="2" align="center"><input type="submit" name="pwsub" value="确认修改" /></td>
		</tr>
	</table>
	</form>
<?php
}
//change username
elseif($mess=='username')
{
	//"修改昵称";
	$username=mysql_query(" SELECT `username` FROM `member` WHERE `uid`='$uid' ");
	$username=mysql_fetch_array($username);
	$username=$username['username'];
	
?>	
	<form action="" method="post" />
	<table border="1" align="center">
		<tr>
			<td align="right">用户名：</td><td><?php echo $username ; ?></td>
		</tr>
		<tr>
			<td align="right">新用户：</td><td><input type="text" name="username" maxlength="25" size="25" /></td>
		</tr>
		<tr>
			<td colspan="2" align="center"><input type="submit" name="unsub" /></td>
		</tr>
	</table>
	</form>
<?php	
	
}
//change headimg
elseif($mess=='headimg')
{	
	$type_name=array(
	
		 'image/pjpeg',
		 'image/jpg',
		 'image/jpeg',
		 'image/gif',
		 'image/png',
		 'image/x-png' 
	);
	
	$max_file_size=500000;
	$upfile_url="photo/";
	
	if(!file_exists($upfile_url))
	{
		mkdir($upfile_url);
	}
	
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
	if (!is_uploaded_file($_FILES["upfile"][tmp_name]))
	{
		 $message= "图片不存在!";
		 header("location:show.php?show=$message");
	}
	
	$file=$_FILES['upfile'];
	
	if($max_file_size<$file['size'])
	{
		 $message= "图片不要超过500K";
		 header("location:show.php?show=$message");
	}
	
	if(!in_array($file['type'],$type_name))
	{
		 $message= "图片类型不匹配".$file['type'];
		 header("location:show.php?show=$message");
	}
	
	$filename=$file['tmp_name'];
	$imagesize=getimagesize($filename);
	$pinfo=pathinfo($file['name']);
	$ftype=$pinfo['extension'];
	$imgdir=$upfile_url.time().".".$ftype;
	
	if(file_exists($imgdir))
	{
		 $message= "此文件名也存在";
		 header("location:show.php?show=$message");
	}
	
	if(!move_uploaded_file($filename,$imgdir))
	{
		 $message= "移动文件出错";
		 header("location:show.php?show=$message");
	}
}

if(isset($_POST['imgsub']))
{
	if(mysql_query(" UPDATE `member` SET `userface`='$imgdir' WHERE `uid`='$uid' "))
	{
		header("location:user_zone.php?uid=$uid");
	}
	else
	{
		$message="未知错误";
		header("location:show.php?show=$message");
	}
}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>头像操作</title>
</head>

<body>
<form enctype="multipart/form-data" method="post"  action="">
<table border="1">
	<tr>
		<td width="150" height="150">
<?php
if(isset($_POST['showsub']))
{	
	echo "<img src=$imgdir width=150 height=150";
}
?>
		</td>
	</tr>
	<tr>
		<td><input name="upfile" type="file"></td>
	</tr>
	<tr>
		<td align="right"><input type="submit" name="showsub" value="浏览" /><input type="submit" name="imgsub" value="上传" /></td>
	</tr>
</table>
</form>

</body>
</html>

<?php 
} ///////////////////headimg finish
?>